/* 引入配置 */
const { QQ_MUSIC_HOST } = require('../../consts');

/* 引入模块 */
// axios
const axios = require('../../plugins/axios');

/* 暴露接口 */
module.exports = (req, res, next) => {

    // 请求头过滤
    let { host, ...headers } = req.headers;

    // 字典修正
    req.body.phone && (req.body.phone = parseInt(req.body.phone));
    req.body.password && (req.body.password = parseInt(req.body.password));

    // 发送请求
    axios({
        method: req.method,
        url: QQ_MUSIC_HOST + '/splcloud' + req.url,
        headers: {
            ...headers,
            referer : "https://c.y.qq.com/",
        },
        params: {
            ...req.query,
            ein: 29,
            categoryId: 10000000,
            format: 'json',
            inCharset: 'utf-8',
            outCharset: 'utf-8'
        },
        data: req.body
    })
        // 监听数据返回
        .then(({ data }) => res.json(data))
        // 监听错误
        .catch(err => console.log(err.stack))
}